﻿using System;

namespace DeploySources.Helper
{
	/// <summary>
	/// Store a single connection parameters
	/// </summary>
	public class ConnectionItem : IEquatable<ConnectionItem>
	{
		/// <summary>
		/// Target Url for the connection
		/// </summary>
		public string Url { get; set; }
		/// <summary>
		/// Artefact file assiciated with the connection
		/// </summary>
		public string ArtefactFile { get; set; }
		/// <summary>
		/// Username for the connection
		/// </summary>
		public string Username { get; set; }
		/// <summary>
		/// Password for the connection
		/// </summary>
		public string Password { get; set; }
		/// <summary>
		/// Identify if the target is SharePoint Online
		/// </summary>
		public bool IsSharePointOnline { get; set; }
		
		/// <summary>
		/// Compare 2 connection items
		/// </summary>
		/// <param name="other">Connection to compare with</param>
		/// <returns>Returns if they are equal</returns>
		public bool Equals(ConnectionItem other)
		{
			return
				other != null &&
				string.Equals(Url, other.Url, StringComparison.InvariantCultureIgnoreCase) &&
				string.Equals(Username, other.Username, StringComparison.InvariantCultureIgnoreCase) &&
				string.Equals(Password, other.Password, StringComparison.InvariantCultureIgnoreCase) &&
				IsSharePointOnline ==  other.IsSharePointOnline;
		}

		/// <summary>
		/// Clone a connection item
		/// </summary>
		/// <returns>Returns a cloned connection item</returns>
		internal ConnectionItem Clone()
		{
			return new ConnectionItem
			{
				Url = Url,
				ArtefactFile = ArtefactFile,
				Username = Username,
				Password = Password,
				IsSharePointOnline = IsSharePointOnline
			};
		}
	}
}
